<?php

namespace ua_backend\models;

use Yii;
use yii\db\ActiveRecord;
use yii\db\Expression;


class Statistics extends ActiveRecord
{
    public static function tableName(){return 'shops_online';}

    public static function getData($uuid){
        $data = self::find()->where([
            'and',
            ['uuid'=>$uuid],
            ['>=', 'event_date', new Expression('CURDATE() - INTERVAL 14 DAY')]
        ])->orderBy('event_date desc, event_time asc')->all();
        return $data;
    }

    public static function rebuild($list,$obj){
        $indexs = Yii::$app->params['timeslots'];
        $index = array_search($obj->event_time, $indexs);
        for($i=0;$i<$index;$i++){
            $list[$obj->event_date][] = '';
        }
        $list[$obj->event_date][] = $obj->count;
        return $list;
    }
}
